/**
 * 过渡动画相关CSS规则模块
 * @version 1.0.0
 */

// 处理过渡动画相关的CSS规则
export function processTransitionRules(className, options = {}) {
    const { platform = 'H5', h5Unit = 'rem', remBase = 16 } = options;
    
    // 过渡动画 - 根据 uni-app x 文档实现
    // 支持格式：transition, transition-300ms, transition-1s, transition-all, transition-colors 等
    const transitionMatch = className.match(/^transition(?:-(.+))?$/);
    if (transitionMatch) {
        const [, suffix] = transitionMatch;
        
        // 基础 transition 类
        if (!suffix) {
            // 根据 uni-app x 文档，默认值调整为 'all'
            if (platform === 'APP-PLUS' || platform === 'APP-ANDROID' || platform === 'APP-IOS') {
                return {
                    'transition-property': 'all',
                    'transition-duration': '150ms',
                    'transition-timing-function': 'ease'
                };
            } else {
                return {
                    'transition': 'all 150ms ease'
                };
            }
        }
        
        // 处理时间相关的 transition 类名
        const durationMatch = suffix.match(/^(\d+(?:\.\d+)?)(ms|s)$/);
        if (durationMatch) {
            const [, numValue, unit] = durationMatch;
            const transitionDuration = `${numValue}${unit}`;
            
            if (platform === 'APP-PLUS' || platform === 'APP-ANDROID' || platform === 'APP-IOS') {
                return {
                    'transition-property': 'all',
                    'transition-duration': transitionDuration,
                    'transition-timing-function': 'ease'
                };
            } else {
                return {
                    'transition': `all ${transitionDuration} ease`
                };
            }
        }
        
        // 处理属性相关的 transition 类名
        const propertyMap = {
            'none': 'none',
            'all': 'all',
            'colors': 'color, background-color, border-color, fill, stroke',
            'opacity': 'opacity',
            'shadow': 'box-shadow',
            'transform': 'transform'
        };
        
        if (propertyMap[suffix]) {
            const transitionProperty = propertyMap[suffix];
            
            if (platform === 'APP-PLUS' || platform === 'APP-ANDROID' || platform === 'APP-IOS') {
                return {
                    'transition-property': transitionProperty,
                    'transition-duration': '150ms',
                    'transition-timing-function': 'ease'
                };
            } else {
                return {
                    'transition': `${transitionProperty} 150ms ease`
                };
            }
        }
        
        // 处理 ease 相关的 transition 类名
        const easingMap = {
            'ease': 'ease',
            'ease-in': 'ease-in',
            'ease-out': 'ease-out',
            'ease-in-out': 'ease-in-out',
            'linear': 'linear'
        };
        
        if (easingMap[suffix]) {
            const transitionTimingFunction = easingMap[suffix];
            
            if (platform === 'APP-PLUS' || platform === 'APP-ANDROID' || platform === 'APP-IOS') {
                return {
                    'transition-property': 'all',
                    'transition-duration': '150ms',
                    'transition-timing-function': transitionTimingFunction
                };
            } else {
                return {
                    'transition': `all 150ms ${transitionTimingFunction}`
                };
            }
        }
    }
    
    // 单独的 transition-duration 类名
    const durationMatch = className.match(/^duration-(\d+(?:\.\d+)?)(ms|s)?$/);
    if (durationMatch) {
        const [, numValue, unit] = durationMatch;
        const transitionDuration = unit ? `${numValue}${unit}` : `${numValue}ms`;
        
        return {
            'transition-duration': transitionDuration
        };
    }
    
    // 单独的 transition-timing-function 类名  
    const easingMatch = className.match(/^ease-(.+)$/);
    if (easingMatch) {
        const [, easingType] = easingMatch;
        const easingMap = {
            'linear': 'linear',
            'in': 'ease-in',
            'out': 'ease-out',
            'in-out': 'ease-in-out'
        };
        
        if (easingMap[easingType]) {
            return {
                'transition-timing-function': easingMap[easingType]
            };
        }
    }
    
    // 单独的 transition-delay 类名
    const delayMatch = className.match(/^delay-(\d+(?:\.\d+)?)(ms|s)?$/);
    if (delayMatch) {
        const [, numValue, unit] = delayMatch;
        const transitionDelay = unit ? `${numValue}${unit}` : `${numValue}ms`;
        
        return {
            'transition-delay': transitionDelay
        };
    }
    
    return null;
} 